package cn.com.utt.unms.controller;

import java.security.Principal;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import cn.com.utt.common.vo.RestResult;
import cn.com.utt.common.vo.TableInput;
import cn.com.utt.common.vo.TableOutput;
import cn.com.utt.common.vo.User;
import cn.com.utt.unms.service.EventLogService;
import cn.com.utt.unms.vo.EventLogInfo;

@RestController
@RequestMapping("v1/eventLogs")
public class EventLogController {
	
	@Autowired 
	private EventLogService eventLogService;
	
	/**
	 * 告警管理--告警信息列表
	 * @param input
	 * @param principal
	 * @return
	 */
	@RequestMapping(value = "/search", method = { RequestMethod.POST }, consumes = "application/json")
	public Map<String, Object> queryEventLogs(@RequestBody TableInput input, Principal principal) {
		Authentication authentication = (Authentication) principal;
		User user = (User) authentication.getPrincipal();
		System.out.println(JSON.toJSONString(input));
		TableOutput<EventLogInfo> output = eventLogService.queryByCondition(input, user.getGroupId(),user.getId());
		RestResult result = new RestResult();
		result.put("start", output.getStart());
		result.put("rows", output.getRows());
		result.put("total", output.getTotal());
		result.put("eventLogs", output.getList());
		return result.toJsonObject();
	}
	
	/**
	 * 首页--告警信息-饼图以及列表
	 * 
	 * @param principal
	 * @param networkId
	 * @return
	 */
	@RequestMapping(value = "eventLogInfo", method = { RequestMethod.POST })
	public Map<String, Object> eventLogInfo(Long networkId) {
		RestResult result = new RestResult();
		result = eventLogService.queryEventLogByType(networkId);
		return result.toJsonObject();
	}

}
